package com.web.exceptionHandle;

import com.core.model.Error;
import com.exception.AdminNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: xf
 * Date: 2016/5/6
 * Time: 22:21
 * To change this template use Editor | File and Code Templates.
 */
@RestController
@ControllerAdvice
public class AdminExceptionHandle {

    @ExceptionHandler(AdminNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public Error adminNotFound(AdminNotFoundException e) {
        return new Error(404, "Admin [" + e.getUsername() + "] not found ");
    }

}
